package com.csl.jmu.demo.entity;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Getter;
import lombok.Setter;
import java.util.List;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;

/**
 * <pre>
 * 描述：角色信
 * </pre>
 *
 * @类名：com.csl.jmu.demo.entity.SysRole
 * @作者： 1410HL0236
 * @创建日期: 2019/11/18 14:58
 */
@Getter
@Setter
@Entity
public class SysRole implements Serializable {
  @Id
  @GeneratedValue
  private Long id;

  private String name;

  private String description;

  @JsonIgnoreProperties(value = {"roles"})
  @ManyToMany(fetch = FetchType.EAGER)
  @JoinTable(name = "SysRolePermission",
          joinColumns = {@JoinColumn(name = "roleId")},
          inverseJoinColumns = {@JoinColumn(name = "permissionId")})
  private List<SysPermission> permissions;

  // 用户 -- 角色关系：多对多
  @JsonIgnoreProperties(value = {"roles"})
  @ManyToMany
  @JoinTable(name = "SysUserRole",
          joinColumns = {@JoinColumn(name = "roleId")},
          inverseJoinColumns = {@JoinColumn(name = "uid")})
  private List<UserInfo> userInfos;// 一个角色对应多个用户

}
